#include "ThriftClient.h"
#include "trace_worker.h"
#include "JsonHelper.h"
#include "ClientManager.h"

CThriftClient::CThriftClient(const rapidjson::Value &configValue)
{
    ConnPoolInit(configValue);
}

CThriftClient::~CThriftClient()
{
}

void CThriftClient::ConnPoolInit(const rapidjson::Value &configValue)
{   trace_worker();
    m_thriftConnPool = CThriftConnPool::instance();
    if (!configValue.HasMember("host") || !configValue.HasMember("port") || !configValue.HasMember("connpool_size"))
    {
        return;
    }
    trace_printf("NULL");
    m_thriftConnPool = new CThriftConnPool;
    m_thriftConnPool->Init(configValue);
}

bool CThriftClient::thriftMethod(std::string& _return, const std::string &openId, const std::string& method, const std::string& reqArgs, bool isSyn)
{
    CThriftConnPool::ThriftMethod thriftMethod = isSyn ? &CThriftConnPool::thriftMethodSyn : &CThriftConnPool::thriftMethod;
    return thriftMethod(m_thriftConnPool, _return, openId, method, reqArgs);
}


